#The dodgeball game :Hello world and Matt
import sys, pygame,os, glob
pygame.init()

size = width,height =640, 640

speedX,speedY=0,0
incrementSize = 100
white = 255, 255, 255
screen = pygame.display.set_mode(size)
ball = pygame.image.load("ball.jpg")
ballrect = ball.get_rect()
ballrect = ballrect.move(512,320)

clock = pygame.time.Clock()

class player:
    def __init_(self):
        self.x = 200
        self.y = 300
        self.ani_speed_init=10
        self.ani_speed=self.ani_speed_init
        self.ani = glob.glob("img/doom_w*.png")
        self.ani.sort
        self.ani_pos =0
        self.ani_max= len(self.ani)-1
        self.img=pygame.image.load(self.ani[0])
        self.update(0)
        
    def update(self, pos):
        if pos != 0:
            self.ani_speed -= 1
            self.x+=pos
            if self.ani_speed == 0:
                self.img = pygame.image.load(self.ani[self.ani_pos])
                self.ani_speed = self.ani_speed_init
                if self.ani_pos == self.ani_max:
                    self.ani_pos=0
                else:
                    self.ani_pos+=1
        print self.ani_pos
        screen.blit(self.img,(self.x,self.y))
           
 
player1 = player()
pos = 0

print "Welcome to Dodgeball"

#Moving a character around
while 1:
    #print "hello world"
    clock.tick(60) #limiting 60 frames per second
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
            
    #check if key pressed
    pygame.event.pump()
    key = pygame.key.get_pressed()
    if key[pygame.K_DOWN]:
        print 'down arrow pressed'
        speedY = incrementSize
    if key[pygame.K_UP]:
        print 'up arrow pressed'
        speedY = -incrementSize
    if key[pygame.K_LEFT]:
        print 'left arrow pressed'
        speedX = -incrementSize
    if key[pygame.K_RIGHT]:
        print 'right arrow pressed'
        speedX = incrementSize
    ballrect=ballrect.move(speedX,speedY)
    speedX=0
    speedY=0
    screen.fill(white)
    #screen.blit(apple,applerect)
    screen.blit(ball, ballrect)
    pygame.display.flip()    
        
        
        
        